// JavaScript Document

//kamus global


//list fungsi
function CekNama(a,b)
{	
	if((/^[A-Za-z\s]{5,50}$/).test(a)) 
	{
		b.innerHTML = "";
		return true;
	}
	else
	{
		b.innerHTML = "min 5 max 50 character, letter and space";
		return false;	
	}
}

function CekUserName(a,b)
{
	if((/^[A-Za-z0-9\._]+@[A-Za-z0-9_]{2,}(\.[A-Za-z0-9_]+)*$/).test(a)) 
	{
		b.innerHTML = "";
		//alert("kodok");
		return true;
	}
	else
	{
		b.innerHTML = "min 5 character letter, number,underscore, and dot";
		//alert("meong");
		return false;	
	}
}

function CekPassword (a,b)
{
	 if((/.{5,30}/).test(a)) 
	{
		b.innerHTML = "";
		return true;
	}
	else
	{
		b.innerHTML = "min 6 max 30 character";
		return false;	
	}
}

function CekDescription (a,b)
{
	 if((/.{0,200}/).test(a)) 
	{
		b.innerHTML = "";
		return true;
	}
	else
	{
		b.innerHTML = "max 200 character";
		return false;	
	}
}

function CekTag (a,b)
{
	 if((/.{0,100}/).test(a)) 
	{
		b.innerHTML = "";
		return true;
	}
	else
	{
		b.innerHTML = "max 100 character";
		return false;	
	}
}

function CekCategory (a,b)
{
	 if((/.{0,100}/).test(a)) 
	{
		b.innerHTML = "";
		return true;
	}
	else
	{
		b.innerHTML = "max 100 character";
		return false;	
	}
}

function CekPasswordB(a,b,c)
{
	if(a == b)
	{
		c.innerHTML ="";
		return true;
	}
	else
	{
		c.innerHTML ="password isn't match";
		return false;	
	}
}

function CekLokasi (a,b)
{
	if((/.{5,40}/).test(a)) 
	{
		b.innerHTML = "";
		return true;
	}
	else
	{
		b.innerHTML = "min 5 max 40 character";
		return false;	
	}
}

function CekTanggal(a,b)
{
	
	if((/^\d{4}\-\d{2}\-\d{2}$/).test(a)) 
	{
		b.innerHTML = "";
		return true;
	}
	else
	{
		b.innerHTML = "format YYYY-MM-DD";
		return false;	
	}
}

function CekHobby (a,b)
{
	if((/.{5,25}/).test(a)) 
	{
		b.innerHTML = "";
		return true;
	}
	else
	{
		b.innerHTML = "min 5 max 25 character";
		return false;	
	}
}

function CekPhotoID(a,b)
{	
	if((/^[0-9\s]{1,}$/).test(a)) 
	{
		b.innerHTML = "";
		return true;
	}
	else
	{
		b.innerHTML = "Invalid Photo ID";
		return false;	
	}
}

function CekPhotoURL (a,b)
{
	if((/^.*\.(bmp|jpeg|jpg|gif|png)$/).test(a)) 
	{
		b.innerHTML = "";
		return true;
	}
	else
	{
		b.innerHTML = "Invalid Photo URL";
		return false;	
	}
}

function CekBodyMessage(a,b)
{
	if((/.{,500}/).test(a)) 
	{
		b.innerHTML = "";
		return true;
	}
	else
	{
		b.innerHTML = "Max Body Message = 500 character";
		return false;	
	}
}

function CekRegistrasi (UserName,Password,PasswordB,Nama,Tanggal,Lokasi,Hobi,Photo,aa,bb,cc,dd,ee,ff,gg,hh)
{
	var a = CekNama(Nama,aa);
	var b = CekUserName(UserName,bb);
	var c = CekPassword(Password,cc);
	var d = CekPasswordB(Password,PasswordB,dd);
	var e = CekTanggal(Tanggal,ee);
	var f = CekLokasi(Lokasi,ff);
	var g = CekHobby(Hobi,gg);
	var h = CekPhotoURL(Photo,hh);
	
	if(a&&b&&c&&d&&e&&f&&g&&h)
	{
		//alert("flickertiew");
		
		//clearForm(document.getElementById("UserRegistration"));
		//x.submit();
		alert("Submitting...");
		return true;
	}
	else
	{
		alert("Ooops... something wrong in your input");	
		//x.elements.focus(1);
		
		return false;
	}
}



function CekGanti(PasswordOld,Password,Password2,Name,Birthday,Lokasi,Hobby,aa,bb,cc,dd,ee,ff,gg)
{
	var a = CekPassword(PasswordOld,aa);
	var b = CekPassword(Password,bb);
	var c = CekPasswordB(Password,Password2,cc);
	var d = CekNama(Name,dd);
	var e = CekTanggal(Birthday,ee);
	var f = CekLokasi(Lokasi,ff);
	var g = CekHobby(Hobby,gg);
	if(a&&b&&c&&d&&e&&f&&g)
	{
		//alert("flickertiew");
		
		//clearForm(document.getElementById("UserRegistration"));
		//x.submit();
		alert("Submitting...");
		return true;
	}
	else
	{
		alert("Ooops... something wrong in your input");	
		//x.elements.focus(1);
		
		return false;
	}
}

function CekGantiPassword(UserName, Password, aa, bb)
{
	var a = CekUserName(UserName,aa);
	var b = CekPassword(Password,bb);
	
	if(a&&b)
	{
		alert("Submitting...");
		return true;
	}
	else
	{
		alert("Ooops... something wrong in your input");	
		return false;
	}
}

function CekBlockUser(UserName, aa)
{
	var a = CekUserName(UserName,aa);
	
	if(a)
	{
		alert("Submitting...");
		return true;
	}
	else
	{
		alert("Ooops... something wrong in your input");	
		return false;
	}
}

function CekGantiUpload(Photo,Deskripsi,Tag,Tanggal,Kategori,aa,bb,cc,dd,ee)
{
	var a = CekPhotoURL(Photo,aa);
	var b = CekDescription(Deskripsi,bb);
	var c = CekTag(Tag,cc);
	var d = CekTanggal(Tanggal,dd);
	var e = CekCategory(Kategori,ee);	
	if(a&&b&&c&&d&&e)
	{
		//alert("flickertiew");
		
		//clearForm(document.getElementById("UserRegistration"));
		//x.submit();
		alert("Submitting...");
		return true;
	}
	else
	{
		alert("Ooops... something wrong in your input");	
		//x.elements.focus(1);
		
		return false;
	}
}